export default class WindowProps {
  data: any

  serialize: () => string

  deserialize: (value: string) => any

  constructor(data: any, serialize: () => string, deserialize: (value: string) => void) {
    this.data = data
    this.serialize = serialize
    this.deserialize = deserialize
  }

  toState() {
    const obj: any = {}
    obj.data = this.serialize()
    obj.serialize = this.serialize.toString()
    obj.deserialize = this.deserialize.toString()
    return obj
  }

  static fromState(obj: any) {
    if (!obj) {
      return
    }
    const deserialize = eval(obj.deserialize) as (value: string) => any
    const data = deserialize(obj.data)
    const serialize = eval(obj.serialize) as () => string
    return new WindowProps(data, serialize, deserialize)
  }
}
